import Axios from "axios";

const NET_ERROR = "Network Error";

const request = Axios.create({
  baseURL:
    process.env.NODE_ENV === "development" ? "http://localhost:8989" : "http://8.136.9.48:8868",
  // timeout: 2500
});

request.interceptors.request.use(
  config => {
    return config;
  },
  err => {
    return Promise.reject(err);
  },
);

request.interceptors.response.use(
  response => {
    return response;
  },
  err => {
    if (err.message === NET_ERROR) {
      return Promise.reject({
        message: "网络错误",
      });
    }
    return Promise.reject(err);
  },
);

export default request;
